/*
  * Copyright 2020 tuhu.cn All right reserved. This software is the
  * confidential and proprietary information of tuhu.cn ("Confidential
  * Information"). You shall not disclose such Confidential Information and shall
  * use it only in accordance with the terms of the license agreement you entered
  * into with Tuhu.cn
  */
package com.nancy.concurrent;

import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Component;
import org.springframework.util.concurrent.ListenableFuture;

import java.util.concurrent.CompletableFuture;

/**
 * @author zhouguangfeng
 * @date 2020/6/12 17:33
 */
@Component
public class AsyncBean {

    @Async("myexecutor")
    public void asyncNoReturn(){
        System.out.println("1 --- AsyncBean asyncNoReturn");
    }

    @Async("myexecutor")
    public ListenableFuture<String> asyncReturnAsyncResult(){
        try {
            Thread.sleep(1000L);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        ListenableFuture<String> asyncResult = AsyncResult.forValue("asyncReturnAsyncResult");
//        throw new RuntimeException("asyncReturnAsyncResult error") ;
        return asyncResult;
    }

    @Async("myexecutor")
    public CompletableFuture<String> asyncReturnCompletableFuture(){
        ListenableFuture<String> asyncResult = AsyncResult.forValue("asyncReturnCompletableFuture");
//        throw new RuntimeException("asyncReturnCompletableFuture error") ;
        return asyncResult.completable();
    }

}
